#define _CRT_SECURE_NO_WARNINGS	

#include<stdio.h>
#include<stdlib.h>

#define MAX_SIZE 110

typedef struct Stack
{
	int* arr;
	int top;
}Stack;

void Init_Stack(Stack* ps)
{
	ps->arr = (int*)malloc(sizeof(int) * MAX_SIZE);
	ps->top = 0;
}

void Push(Stack* ps, int val)
{
	ps->arr[ps->top++] = val;
}

void Pop(Stack* ps)
{
	ps->top--;
}

int Top(Stack* ps)
{
	return ps->arr[ps->top - 1];
}

bool Empty(Stack* ps)
{
	return ps->top == 0;
}

void Destroy(Stack* ps)
{
	free(ps->arr);
	ps->arr = NULL;
	ps->top = 0;
}

typedef struct
{
	Stack s1;
	Stack s2;
} MyQueue;

MyQueue* myQueueCreate()
{
	MyQueue* mq = (MyQueue*)malloc(sizeof(MyQueue));

	Init_Stack(&mq->s1);
	Init_Stack(&mq->s2);

	return mq;
}

void myQueuePush(MyQueue* obj, int x)
{
	Push(&obj->s1, x);
}

int myQueuePop(MyQueue* obj)
{
	int rel = 0;
	if (!Empty(&obj->s1) || !Empty(&obj->s2))
	{
		if (Empty(&obj->s2))
			while (!Empty(&obj->s1))
			{
				Push(&obj->s2, Top(&obj->s1));
				Pop(&obj->s1);
			}
		rel = Top(&obj->s2);
		Pop(&obj->s2);
	}
	return rel;
}

int myQueuePeek(MyQueue* obj)
{

	if (Empty(&obj->s2))
		while (!Empty(&obj->s1))
		{
			Push(&obj->s2, Top(&obj->s1));
			Pop(&obj->s1);
		}
	return Top(&obj->s2);

}

bool myQueueEmpty(MyQueue* obj)
{
	return !(!Empty(&obj->s1) || !Empty(&obj->s2));
}

void myQueueFree(MyQueue* obj)
{
	Destroy(&obj->s1);
	Destroy(&obj->s2);

	free(obj);
	obj = NULL;
}

/**
 * Your MyQueue struct will be instantiated and called as such:
 * MyQueue* obj = myQueueCreate();
 * myQueuePush(obj, x);

 * int param_2 = myQueuePop(obj);

 * int param_3 = myQueuePeek(obj);

 * bool param_4 = myQueueEmpty(obj);

 * myQueueFree(obj);
*/